package com.dzsw.vue.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    /**
     * 设置允许跨域
     */
    @Override
    protected void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //允许跨域的头信息
                .allowedHeaders("*")
                //允许跨域的Method
                .allowedMethods("*")
                //Access-Control-Max-Age 预检请求结果的缓存时间(秒)
                .maxAge(1800)
                //允许跨域的来源
                .allowedOrigins("*")
                //对许cookie
                .allowCredentials(true);
    }
}
